
//
//  AnimationViewController.m
//  News
//
//  Created by weige on 16/6/6.
//  Copyright © 2016年 weige. All rights reserved.
//

#import "AnimationViewController.h"

@interface AnimationViewController ()
{
    CALayer *transitionlayer;
    CALayer *animationBigLayers;
       
}
@end

@implementation AnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)addProductAnimation:(UIImageView *)imageView
{
    
    
    CGRect fram=imageView.frame;
    NSLog(@"%f",fram.size.width);
    transitionlayer=[CALayer layer];
    transitionlayer.frame=fram;
    transitionlayer.contents=imageView.layer.contents;
    [self.view.layer addSublayer:transitionlayer];
    
    CGPoint p1= transitionlayer.position;
    NSLog(@"p1.x=%f,p1.y=%f",p1.x,p1.y);
    CGPoint p3=CGPointMake(fram.size.width-fram.size.width/4-fram.size.width/8-6, self.view.layer.bounds.size.height-40);
    NSLog(@"self.view.layer.bounds.size.height-40=%f",self.view.layer.bounds.size.height-40);
    
    CAKeyframeAnimation *keyanimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    //
    CGMutablePathRef  path=CGPathCreateMutable();
    CGPathMoveToPoint(path, nil, p1.x, p1.y);
    CGPathAddCurveToPoint(path, nil, p1.x, p1.y-30, p3.x, p1.y-30, p3.x, p3.y);
    keyanimation.path=path;
    
    CABasicAnimation *basicAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
    //设置初始和结束位置
    basicAnimation.fromValue=[NSNumber numberWithFloat:1.0F];
    basicAnimation.toValue=[NSNumber numberWithFloat:.9F];
    basicAnimation.fillMode=kCAFillModeBackwards;
    basicAnimation.removedOnCompletion=YES;
    
    CABasicAnimation *tranformbasicAnimation=[CABasicAnimation animationWithKeyPath:@"transform"];
    CATransform3D fromValue=CATransform3DIdentity;
    tranformbasicAnimation.fromValue=[NSValue valueWithCATransform3D:fromValue];
    tranformbasicAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity, 0.2, 0.2, 1)];
    
    //动画组
    CAAnimationGroup *animationGroup=[CAAnimationGroup animation];
    animationGroup.animations=@[keyanimation,basicAnimation,tranformbasicAnimation];
    animationGroup.duration=.8;
    animationGroup.delegate=self;
    
    [transitionlayer addAnimation:animationGroup forKey:@"car"];
    CGPathRelease(path);
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
